//
// Created by 谢哲 on 2021/5/8.
//

#include <iostream>
#include <vector>
using namespace std;
constexpr unsigned long long mod = 1e9+7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;

    vector<unsigned long long> vdata(5001, 0);
    for (int i=0; i<n; ++i) {
        int a;
        cin >> a;
        vdata[a]++;
    }

    unsigned long long ans = 0;
    for (int len=1; len<=5000; ++len) {
        if (vdata[len] < 2) continue;
        // i, i, i, 0
        unsigned long long cur_ans = 0ull;
        if (vdata[len] >= 3) {
            cur_ans = (vdata[len] * (vdata[len]-1ull) * (vdata[len]-2ull) / 6ull) % mod;
            cur_ans = (cur_ans * vdata[0]) % mod;
        }

        // i, i, a, b
        unsigned long long double_ans = (vdata[len] * (vdata[len]-1) / 2ull) % mod;
        for (int a=1, b=len-1; a<=b; ++a,--b) {
            if (a==b) {
                cur_ans = (cur_ans + ((vdata[a] * (vdata[a]-1) / 2ull) % mod) * double_ans) % mod;
                continue;
            }
            cur_ans = (cur_ans + ((vdata[a] * vdata[b]) % mod * double_ans) % mod) % mod;
        }

        ans = (ans + cur_ans) % mod;
    }

    cout << ans;

    return 0;
}
